package com.lanju.common;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.lanju.controller.WeiXinInterfaceController;
import com.lanju.dao.AdminPermissionDao;
import com.lanju.dao.SystemAdminDao;
import com.lanju.service.JedisService;


public class RequestOperInterceptor extends HandlerInterceptorAdapter{
    
    private static final Logger LOGGER = LoggerFactory.getLogger(RequestOperInterceptor.class);
    
    
    @Autowired
    SystemAdminDao systemAdminDao;
    
    @Autowired
    AdminPermissionDao adminPermissionDao;
    
	@Resource
	JedisService jedisService;
    
    
    Map<String,String> operationInterceptorMap;
    public Map<String, String> getOperationInterceptorMap() {
        return operationInterceptorMap;
    }

    public void setOperationInterceptorMap(
            Map<String, String> operationInterceptorMap) {
        this.operationInterceptorMap = operationInterceptorMap;
    }
    
    @Override
    @ResponseBody
    public boolean preHandle(HttpServletRequest request,
            HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession(true);
        LOGGER.debug("===========ControllerInterceptor preHandle——URI：" + request.getRequestURI());
        LOGGER.info("url="+request.getRequestURI());
        String servletPath = request.getServletPath();
        Object obj=session.getAttribute("userModel");
        boolean flag=false;
        if(obj ==null){
        	LOGGER.info("用户尚未登录");
        	WeiXinInterfaceController weixinInf=new WeiXinInterfaceController();
        	weixinInf.Login(request, response);
        	response.setContentType("application/Json;charset=UTF-8");
            response.setStatus(403);
            response.setHeader("sessionstatus", "timeout");
            response.setHeader("CONTEXTPATH", request.getContextPath()+ "/jsp/login.html");
        	return true; 
        }else{
        	return true;
        }
		
    	
    }

	@Override
	public void postHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		
	}

	@Override
	public void afterCompletion(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
	}

	@Override
	public void afterConcurrentHandlingStarted(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
	}
    
    

}
